<link rel="stylesheet" th:href="@{/assets/css/colorbox.css}" />
<link rel="stylesheet" type="text/css" th:href="@{/ztree/css/zTreeStyle.css}"/>
<link rel="stylesheet" th:href="@{/webuploader/webuploader.css}"/>
<link rel="stylesheet" type="text/css" th:href="@{/My97DatePicker/skin/WdatePicker.css}"/>
<head th:include="fragments/head::header" />
<body>
<div class="main-container" id="main-container">
    <div class="main-container-inner">
        <div th:include="fragments/left::left" class="sidebar" id="sidebar"></div>
        <div class="main-content">
            <div class="page-content">
                <form method="post" id="edit">
                    <input type="hidden" name="id" id="id" th:value="${role!=null}? ${role.id}"/>
                    <div  class="tab-pane fade in active">
                        <ul id="roleTree" class="ztree"></ul>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" id="submits">保存</button>
                    </div>

                    <div id="alert" class="alert alert-success" style="display: none;" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <span id="alertText"></span>
                    </div>
                </form>

            </div>
        </div>
        <!--<div th:include="fragments/bottom::bottom"></div>-->
    </div>

    <a href="#" id="btn-scroll-up"
       class="btn-scroll-up btn btn-sm btn-inverse"> <i
            class="icon-double-angle-up icon-only bigger-110"></i>
    </a>
</div>

<!-- Modal备注 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">

        </div>
    </div>
</div>



<div th:include="fragments/js::js"></div>


<!-- page specific plugin scripts -->
<script th:src="@{/assets/js/jquery.dataTables.min.js}"></script>
<script th:src="@{/assets/js/jquery.dataTables.bootstrap.js}"></script>
<script type="text/javascript" th:src="@{/ztree/js/jquery.ztree.core-3.5.min.js}"></script>
<script type="text/javascript" th:src="@{/ztree/js/jquery.ztree.excheck-3.5.min.js}"></script>
<script th:src="@{/assets/js/temp.js}" charset="UTF-8"></script>
<script th:src="@{/bootstrap/js/star-rating.min.js}"></script>
<!--ueditor-->
<script type="text/javascript" charset="utf-8" th:src="@{/UEditor/ueditor.config.js}"></script>
<script type="text/javascript" charset="utf-8" th:src="@{/UEditor/ueditor.all.min.js}"></script>
<script type="text/javascript" charset="utf-8" th:src="@{/UEditor/lang/zh-cn/zh-cn.js}"></script>
<script type="text/javascript">
    $(function () {
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        var transferId = parent.$("#id").val(); //转案Id
        var saveId = parent.$("#callback_index").val(); //保存选中人员的input的id
        var countryBussId = parent.$("#countryBussId").val();
        var queryType = parent.$("#queryType").val();

        //保存操作
        $("#submits").click(function () {
            var tree = $.fn.zTree.getZTreeObj("roleTree");
            var nodes = tree.getNodesByParam("checked", true, null);
            var len = nodes.length;
            console.log(nodes.length);
            if(len > 0){
                parent.$('#'+saveId+'no').val(nodes[0].id);
                parent.$('#'+saveId+'name').val(nodes[0].name);
            }
            parent.layer.close(index);
        })

        //监听modal关闭事件，清除整个页面的缓存数据
        $("#myModal").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });

        //ztree配置
        var setting =
            {
                check:
                    {
                        enable: true,
                        chkStyle: "radio",
                        radioType: "all",
                    },
                data:
                    {
                        simpleData:
                            {
                                enable: true
                            },
                        keep:
                            {
                                parent: true
                            }
                    },
                callback:
                    {
                        beforeExpand: zTreeBeforeExpand,
//                        onCheck: zTreeOnCheck,
                    onExpand: zTreeOnExpand,
                    onClick:onClick
                }
            };
        function onClick(event, treeId, treeNode)
        {
            var tree = $.fn.zTree.getZTreeObj("roleTree");
            tree.checkNode(treeNode, !treeNode.checked, true, true);
        }
        //展开方法前触发
        function zTreeBeforeExpand(treeId, treeNode) {
            var tree = $.fn.zTree.getZTreeObj("roleTree");
            tree.removeChildNodes(treeNode);
            return true;
        };
        //加载展开方法
        function zTreeOnExpand(event, treeId, treeNode)
        {
            var treeNodeId = treeNode.id;
            $.post('/transfer/groupLeaderData',
                {
                    parentId : treeNodeId,
                    countryBussId : countryBussId,
                    queryType : queryType,
                },
                function(data)
                {
                    if (data.success)
                    {
                        var dbDate = eval(data.msg);
                        var tree = $.fn.zTree.getZTreeObj("roleTree");
                        tree.addNodes(treeNode, dbDate);
                    }
                }
            );
        }

        $(function()
        {
            $.post(
                '/transfer/groupLeaderData',
                {
                    countryBussId : countryBussId,
                    queryType : queryType,
                },
                function(data){
                    if (data.success) {
                        var dbDate = eval(data.msg);
                        $.fn.zTree.init($("#roleTree"), setting, dbDate);
                    }
                }
            );
        });
    });
</script>
<!--图片查看器-->
<script th:src="@{/assets/js/jquery.colorbox-min.js}"></script>
<script th:src="@{/layer/layer.js}"></script>
</body>